import {Component, OnInit} from '@angular/core';
import {DeviceService} from '../../svc/device.svc';
import {ActivatedRoute, Router} from '@angular/router';
import {PlatformLocation} from '@angular/common';
import {MenuItem} from 'primeng/api';

import {TreeNode} from 'primeng/api';

// 国际化
import {TranslateService} from '@ngx-translate/core';

@Component({
    selector: 'app-home',
    templateUrl: './home.component.html',
    styleUrls: ['./home.component.css']
})
export class HomeComponent {
    nodes: TreeNode[] = [];

    routeSwitch = false;

    languageType = [
        {language: 'Chinese (Simplified)'},
        {language: 'Cantonese (Traditional)'},
        {language: 'English'},
    ];
    selectedLanguage = {language: 'English'};

    // public displayHelpDialog = false;
    public displayOptionsDialog = false;
    displayHelp = false;

    constructor(public devSvc: DeviceService, private router: Router, private route: ActivatedRoute,  public translateService: TranslateService) {
        this.translateService.addLangs(['cn', 'en']);
        this.translateService.setDefaultLang('en');
        this.initPage();
        this.route.params.subscribe(p => {
            console.log('Go to base href.');
        });
    }

    openHelpDialog(): void {
        this.displayHelp = true;
    }

    openOptionsMenu(): void {
        this.displayOptionsDialog = true;
    }

    initPage(): void {
        this.nodes = this.devSvc.nodesOne;
    }

    onRedirectionHome(): void {
        this.router.navigate(['/home/system-information']);
        this.devSvc.selectLink = this.devSvc.nodesOne[0];
    }

    onClickNavigate(event): void {
        this.router.navigate([event.node.data]);
    }

    openRouteSwitchClick(): void {
        this.routeSwitch = true;
    }

    closeRouteSwitchClick(): void {
        this.routeSwitch = false;
    }

    selectLanguageClick(): void {
        if (this.selectedLanguage.language === 'Chinese (Simplified)') {
	    this.translateService.setDefaultLang('cn');
            this.devSvc.nodesOne[0].label = '系统信息';
            this.devSvc.nodesOne[1].label = '监控';
            this.devSvc.nodesOne[1].children[0].label = '运动状态';
            this.devSvc.nodesOne[1].children[1].label = '心率';
            this.devSvc.nodesOne[1].children[2].label = '心率变异度';
            this.devSvc.nodesOne[1].children[3].label = '呼吸频率';
            this.devSvc.nodesOne[1].children[4].label = '每搏输出量';
            this.devSvc.nodesOne[2].label = '警报通知';
            this.devSvc.nodesOne[2].children[0].label = '服务端';
            this.devSvc.nodesOne[2].children[1].label = '接收端';
            this.devSvc.nodesOne[3].label = '设备设置';
            this.devSvc.nodesOne[3].children[0].label = '数据通信';
            this.devSvc.nodesOne[3].children[1].label = '身份验证';
            this.devSvc.nodesOne[3].children[2].label = '网络';
            this.devSvc.nodesOne[3].children[3].label = '固件升级';

/*            this.devSvc.nodesOne[4].label = '传感器设置';
            this.devSvc.nodesOne[4].children[0].label = '校准';
            this.devSvc.nodesOne[4].children[1].label = '高级设置';*/

            this.devSvc.onChangeLanguage();
        }
        if (this.selectedLanguage.language === 'Cantonese (Traditional)') {
            this.translateService.setDefaultLang('cn_ca');
            this.devSvc.nodesOne[0].label = '系統信息';
            this.devSvc.nodesOne[1].label = '監控';
            this.devSvc.nodesOne[1].children[0].label = '運動狀態';
            this.devSvc.nodesOne[1].children[1].label = '心率';
            this.devSvc.nodesOne[1].children[2].label = '心率變異度';
            this.devSvc.nodesOne[1].children[3].label = '呼吸頻率';
            this.devSvc.nodesOne[1].children[4].label = '每博輸出量';
            this.devSvc.nodesOne[2].label = '警報通知';
            this.devSvc.nodesOne[2].children[0].label = '服務端';
            this.devSvc.nodesOne[2].children[1].label = '接收端';
            this.devSvc.nodesOne[3].label = '設備設置';
            this.devSvc.nodesOne[3].children[0].label = '數據通信';
            this.devSvc.nodesOne[3].children[1].label = '身份驗證';
            this.devSvc.nodesOne[3].children[2].label = '網絡';
            this.devSvc.nodesOne[3].children[3].label = '固件升級';

/*            this.devSvc.nodesOne[4].label = '傳感器設置';
            this.devSvc.nodesOne[4].children[0].label = '校準';
            this.devSvc.nodesOne[4].children[1].label = '高級設置';*/

            this.devSvc.onChangeLanguage();
        }
        if (this.selectedLanguage.language === 'English') {
            this.translateService.setDefaultLang('en');
            this.devSvc.nodesOne[0].label = 'System Information';
            this.devSvc.nodesOne[1].label = 'Monitoring';
            this.devSvc.nodesOne[1].children[0].label = 'Motion Status';
            this.devSvc.nodesOne[1].children[1].label = 'Heart Rate';
            this.devSvc.nodesOne[1].children[2].label = 'Heart Rate Variability';
            this.devSvc.nodesOne[1].children[3].label = 'Respiration Rate';
            this.devSvc.nodesOne[1].children[4].label = 'Stroke Volume';
            this.devSvc.nodesOne[2].label = 'Alert Notification';
            this.devSvc.nodesOne[2].children[0].label = 'Service';
            this.devSvc.nodesOne[2].children[1].label = 'Receivers';
            this.devSvc.nodesOne[3].label = 'Device Settings';
            this.devSvc.nodesOne[3].children[0].label = 'Data Communication';
            this.devSvc.nodesOne[3].children[1].label = 'Authentication';
            this.devSvc.nodesOne[3].children[2].label = 'Network';
            this.devSvc.nodesOne[3].children[3].label = 'Firmware Upgrade';

/*            this.devSvc.nodesOne[4].label = 'Bed Sensor Settings';
            this.devSvc.nodesOne[4].children[0].label = 'Calibration';
            this.devSvc.nodesOne[4].children[1].label = 'Advanced Settings';*/

            this.devSvc.onChangeLanguage();
        }
    }
}
